<?php
/**
* Sidebars
*/
	$custom_sidebar_position = get_post_meta($post->ID, 'custom_sidebar_position', true);
	$custom_sidebar_id = get_post_meta($post->ID, 'custom_sidebars', true);

	$have_custom_sidebar = false;
	if ( $custom_sidebar_id != 'no_custom_sidebar' && $custom_sidebar_id != '' )
		$have_custom_sidebar = true;

	if 	( $have_custom_sidebar && ( $custom_sidebar_position == "custom_sidebar_only" ) )
	{
		echo '<ul class="widget_content">';
            dynamic_sidebar( 'custom_sidebar_'.$custom_sidebar_id );
		echo '</ul>';
	}

	else
	{	
		if ( $have_custom_sidebar && ( $custom_sidebar_position == "custom_sidebar_before_before" ) )
		{
			echo '<ul class="widget_content">';
				dynamic_sidebar( 'custom_sidebar_'.$custom_sidebar_id );
			echo '</ul>';
		}
		
		if ( is_active_sidebar( 'before_all_widget_area' ) )
		{
			echo '<ul class="widget_content">';
				dynamic_sidebar( 'before_all_widget_area' );
			echo '</ul>';
		}
		
		if ( $have_custom_sidebar && ( $custom_sidebar_position == "custom_sidebar_after_before" ) )
		{
			echo '<ul class="widget_content">';
				dynamic_sidebar( 'custom_sidebar_'.$custom_sidebar_id );
			echo '</ul>';
		}
	
		if ( is_single() && !is_singular( 'portfolios' ) )
		{
			if ( is_active_sidebar( 'single_widget_area' ) )
			{
				echo '<ul class="widget_content">';
					dynamic_sidebar( 'single_widget_area' );
				echo '</ul>';
			}
		}
		
		if ( is_page() )
		{
			if ( is_active_sidebar( 'page_widget_area' ) )
			{
				echo '<ul class="widget_content">';
					dynamic_sidebar( 'page_widget_area' );
				echo '</ul>';
			}
		}
		
		if ( is_singular( 'portfolios' ) )
		{
			if ( is_active_sidebar( 'portofolios_widget_area' ) )
			{
				echo '<ul class="widget_content">';
					dynamic_sidebar( 'portofolios_widget_area' );
				echo '</ul>';
			}
		}
		
		if ( is_category() )
		{
			if ( is_active_sidebar( 'category_widget_area' ) )
			{
				echo '<ul class="widget_content">';
					dynamic_sidebar( 'category_widget_area' );
				echo '</ul>';
			}
		}
	
		if ( is_archive() )
		{
			if ( is_active_sidebar( 'archive_widget_area' ) )
			{
				echo '<ul class="widget_content">';
					dynamic_sidebar( 'archive_widget_area' );
				echo '</ul>';
			}
		}
		
		if ( is_search() )
		{
			if ( is_active_sidebar( 'search_widget_area' ) )
			{
				echo '<ul class="widget_content">';
				   dynamic_sidebar( 'search_widget_area' );
				echo '</ul>';
			}
		}
		
		if ( is_active_sidebar( 'bottom_widget_area' ) )
		{
			echo '<ul class="widget_content">';
				dynamic_sidebar( 'bottom_widget_area' );
			echo '</ul>';
		}
		
		// AFTER BEGIN
		if 	( $have_custom_sidebar && ( $custom_sidebar_position == "custom_sidebar_after" ) )
		{
			echo '<ul class="widget_content">';
				dynamic_sidebar( 'custom_sidebar_'.$custom_sidebar_id );
			echo '</ul>';
		}
		// AFTERU END
	}

?>
